﻿using System.Collections.Generic;
using UnityEngine;

// 用来显示激发的collider，要不有的时候，collider会一闪就没了
public class ColliderManager
{
    #region
    private static ColliderManager m_instance;
    public static ColliderManager Instance()
    {
        if (m_instance == null)
        {
            m_instance = new ColliderManager();
            m_instance.DoInit();
        }
        return m_instance;

    }
    #endregion
    string keyRootName = "ColliderManagerRoot";
    GameObject m_Root = null;
    public Transform GetRootTransform()
    {
        if (m_Root == null)
        {
            m_Root = GameObject.Find(keyRootName);
            if (m_Root == null)
                m_Root = new GameObject(keyRootName);
        }
        return m_Root.transform;
    }

    public void DoInit()
    {
        m_Temple.Add(EType.Circle, typeof(ColliderCore_Circle));
        m_Temple.Add(EType.Box, typeof(ColliderCore_Box));
        m_Temple.Add(EType.Ellipse, typeof(ColliderCore_Ellipse));
        m_Temple.Add(EType.Sector, typeof(ColliderCore_Sector));
        //m_Temple.Add(EType.Ball, typeof(ColliderCore_Circle));
    }
    // Use this for initialization
    public enum EType
    {
        Circle,
        Box,
        Ellipse,
        Sector,
        Ball,
    }

    Dictionary<EType, System.Type> m_Temple = new Dictionary<EType, System.Type>();
    ColliderCore CreateColliderCore(EType type)
    {
        if (!m_Temple.ContainsKey(type))
        {
            XKLog.LogError("没有这种类型{0}", EnumTools.GetEnumDescriptionList(typeof(EType))[(int)type]);
            return null;
        }
        GameObject core = new GameObject();
        var com = core.AddComponent(m_Temple[type]) as ColliderCore;
        return com;
    }
    //圆形
    public ColliderCore DoAddCircle(float fRadius)
    {
        var circle = CreateColliderCore(EType.Circle) as ColliderCore_Circle;
        circle.DoInit(fRadius);
        return circle;
    }
    //  矩形
    public ColliderCore DoAddBox(float fWidth, float fLenght)
    {
        var circle = CreateColliderCore(EType.Box) as ColliderCore_Box;
        circle.DoInit(fWidth, fLenght);
        return circle;
    }
    // 椭圆
    public ColliderCore DoAddEllipse(float fMinRadius, float fMaxRadius)
    {
        var circle = CreateColliderCore(EType.Ellipse) as ColliderCore_Ellipse;
        circle.DoInit(fMinRadius, fMaxRadius);
        return circle;
    }
    // 扇形
    public ColliderCore DoAddSector(float fStartAngel, float fRadius, float fAngle)
    {
        var circle = CreateColliderCore(EType.Sector) as ColliderCore_Sector;
        circle.DoInit(fStartAngel, fRadius, fAngle);
        return circle;
    }

}
